package com.bee2c.osgi.invoke.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.bee2c.osgi.invoke.service.BeeClientInvokeHandler;
import com.bee2c.osgi.invoke.service.BeePlatInvokeHandler;
import com.bee2c.pub.util.bean.ProcessResult;

@RestController
@RequestMapping("/beeosig")
public class BeeosgiController {

	@Autowired
	private BeeClientInvokeHandler client;

	@Autowired
	private BeePlatInvokeHandler plat;

	private final Logger log = LoggerFactory.getLogger(this.getClass());

	@RequestMapping(value = "/client", method = RequestMethod.POST)
	public ProcessResult client(@RequestParam("bcId") String bcId, @RequestParam("groupId") Integer groupId,
			@RequestBody JSONObject paraJson) {
		try {
			Object o = client.distributeInvoke(bcId, groupId, paraJson);
			return ProcessResult.success(o);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			return ProcessResult.fail("调用BEEOSGI客户端服务异常:" + e.getMessage());
		}
	}

	@RequestMapping(value = "/platform", method = RequestMethod.POST)
	public ProcessResult platform(@RequestParam("bcId") String bcId, @RequestBody JSONObject paraJson) {
		try {
			Object o = plat.distributeInvoke(bcId, paraJson);
			return ProcessResult.success(o);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			return ProcessResult.fail("调用BEEOSGI运营端服务异常:" + e.getMessage());
		}
	}
}
